import requests
from bs4 import BeautifulSoup

headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Cookie': 'dy_did=b489fd37f20f9b8770d99e3b00011501; acf_did=b489fd37f20f9b8770d99e3b00011501; Hm_lvt_e99aee90ec1b2106afe7ec3b199020a7=1531133180,1531186908; Hm_lpvt_e99aee90ec1b2106afe7ec3b199020a7=1531187485',
    'Host': 'www.douyu.com',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',
}

def get_html(url,params=None):
    html = requests.get(url=url,headers=headers)
    return html.text

def deal_data(html):
    soup = BeautifulSoup(html,'lxml')
    name = soup.select('#live-list-contentbox .title')
    href = soup.select('#live-list-contentbox ')

def post_html():
    data=requests.post('http://www.douyu.com/lapi/live/getPlay/4689572',headers=headers)
    resp=data.json()
    rtmp_url=resp['data']['rtmp_url']+'/'+resp['data']['rtmp_live']
    return rtmp_url

def main():
    # url = 'https://www.douyu.com/directory'
    # html = get_html(url)
    # deal_data(html)
    post_html()


if __name__ == '__main__':
    main()